package com.ahui.util;

/**
 * @author : ph.li
 * @date : 2023/7/28 16:45
 */
public class SqlUtil {
    // 去除多行注释
    public static String removeMultiLineComments(String secondLine) {
        int firstFlag = secondLine.indexOf("<!--");
        if (firstFlag == -1){
            return secondLine;
        }else {
            int lastFlag = secondLine.indexOf("-->");
            secondLine = secondLine.substring(0,firstFlag) + secondLine.substring(lastFlag,secondLine.length());
            return removeMultiLineComments(secondLine);
        }
    }

    // 去除单行注释
    public static String removeSinglelineComments(String line) {
        line.trim();
        int zhushi = line.indexOf("--");
        if (zhushi == -1){
            return line;
        }else if (zhushi == 0){
            return "";
        }else {
            return line.substring(0,zhushi);
        }
    }

    //转换驼峰结构
    public static String convertHump(String fieldName) {
        String[] fieldArr = fieldName.split("_");
        String newStr = "";
        for (int i = 0; i < fieldArr.length; i++) {
            char[] chars = fieldArr[i].toCharArray();
            chars[0] = toUpperCase(chars[0]);
            newStr += String.valueOf(chars);
        }
        return newStr;
    }

    //转换小驼峰结构
    public static String converSmalltHump(String fieldName) {
        String[] fieldArr = fieldName.split("_");

        if (fieldArr.length == 1){
            return fieldName.toLowerCase();
        }else {
            String newStr = fieldArr[0];
            for (int i = 1; i < fieldArr.length; i++) {
                char[] chars = fieldArr[i].toCharArray();
                chars[0] = toUpperCase(chars[0]);
                newStr += String.valueOf(chars);
            }
            return newStr;
        }

    }

    // 转换大写
    public static char toUpperCase(char c) {
        if (97 <= c && c <= 122) {
            c ^= 32;
        }
        return c;
    }

    // 类型匹配
    public static String typeMatching(String currentFildInfo) {
        if (currentFildInfo.contains("VARCHAR")){
            return "String";
        } else if (currentFildInfo.contains("NUMBER")) {
            return "Integer";
        } else if (currentFildInfo.contains("TIMESTAMP")) {
            return "Data";
        }else if (currentFildInfo.contains("NVARCHAR2")) {
            return "String";
        }else if (currentFildInfo.contains("CHAR")) {
            return "String";
        }else if (currentFildInfo.contains("NCHAR")) {
            return "String";
        }else if (currentFildInfo.contains("CLOB")) {
            return "String";
        }else if (currentFildInfo.contains("NCLOB")) {
            return "String";
        }else if (currentFildInfo.contains("BINARY_FLOAT")) {
            return "Float";
        }else if (currentFildInfo.contains("BINARY_DOUBLE")) {
            return "Double";
        }
        return "String";
    }
}
